package com.ccjq.shosestore.shoppingcart.service.Impl;/*
 * @program: shosestore-parent
 * @description: shopcarte实现类
 * @author: Danst
 * @create: 2019-04-08 14:10
 * @version:1.0
 */

import com.ccjq.shosestore.shoppingcart.bo.ShopcartBo;
import com.ccjq.shosestore.shoppingcart.dao.ShopcartDao;
import com.ccjq.shosestore.shoppingcart.dao.impl.ShopcartDaoImpl;
import com.ccjq.shosestore.shoppingcart.service.Shopcart;

import java.util.ArrayList;
import java.util.List;

public class ShopcartImpl implements Shopcart {

    private ShopcartDao sh;

    public ShopcartImpl() {
        sh = new ShopcartDaoImpl();
    }


    public List<ShopcartBo> inserShopcart() {
        return null;
    }

    /**
     * 根据商品ID查询库存量
     *
     * @param prid
     * @return
     */
    public boolean selectstock(String prid) {
        return sh.selectstock(prid);
    }

    public List<ShopcartBo> insertCar(String carid, String prid, int quantity, String userid) {
        return sh.insertCar(carid,prid,quantity,userid);
    }

    public List<ShopcartBo> selectCar(String userid) {

        List<ShopcartBo> list1 = sh.selectCar(userid);
        List<ShopcartBo> list = new ArrayList<ShopcartBo>();
        for (ShopcartBo sb : list1) {
            ShopcartBo bb = new ShopcartBo();
            bb.setShopping_cart_id(sb.getShopping_cart_id());
            bb.setProduct_id(sb.getProduct_id());
            bb.setQuantity(sb.getQuantity());
            bb.setUser_id(sb.getUser_id());
            bb.setFeature(sb.getFeature());
            bb.setImgpath(sb.getImgpath());
            bb.setPrice(sb.getPrice());
            bb.setXiaoji(sb.getPrice() * sb.getQuantity());
            list.add(bb);
        }

        return list;
    }

    public void deleteCar(String carid) {
        sh.deleteCar(carid);
    }

    public boolean selectOldqu(String prid,int quantity) {

        return sh.selectOldqu(prid,quantity);
    }

    public void update(String prid,String usrid,int quantity) {
        sh.update(prid,usrid,quantity);
    }
}
